<?php

namespace App\Providers;

use App\Http\model\Article;
use App\Http\Model\Category;
use App\Http\Model\Images;
use App\Http\Model\Question;
use App\Http\Model\Video;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        /*橡木板传递公共的数据*/
//        $aRecycleBinNum=Article::where(['status'=>0,'user_id'=>Session::get('admin')['id']])->count();
//        $ArticleNum=Article::where(['status'=>1,'user_id'=>Session::get('admin')['id']])->count();
//        $iRecycleBinNum=Images::where(['status'=>0,'user_id'=>Session::get('admin')['id']])->count();
//        $ImageNum=Images::where(['status'=>1,'user_id'=>Session::get('admin')['id']])->count();
//        $vRecycleBinNum=Video::where(['status'=>0,'user_id'=>Session::get('admin')['id']])->count();
//        $VideoNum=Video::where(['status'=>1,'user_id'=>Session::get('admin')['id']])->count();
        $question=Question::select('user.username','user.avatar','question.created_at','question.question')
            ->join('user','user.id','=','question.from_user','left')->where('question.is_read',0)->orderBy('question.id','desc')
            ->limit(5)->get()->all();
        $category[1]=Category::where(['type'=>1,'status'=>1])->limit(9)->get()->all();
        $category[2]=Category::where(['type'=>2,'status'=>1])->limit(9)->get()->all();
        $category[3]=Category::where(['type'=>3,'status'=>1])->limit(9)->get()->all();
        View::share('Num',['6'=>$category,'7'=>$question]);
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}
